package com.study.boot.config;

import com.study.boot.event.pub.AnotherPublisher;
import com.study.boot.event.pub.NotifyPublisher;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;

/**
 * @author fangdengfu
 * @date 2020/7/4 9:42
 */
@Component
public class AuthenticationCenterApplication implements CommandLineRunner {

    @Resource
    NotifyPublisher notifyPublisher;
    @Resource
    AnotherPublisher anotherPublisher;

    @Override
    public void run(String... args) throws Exception {
        AtomicInteger loop = new AtomicInteger(1);
        while (loop.get() < 10) {
            String msg = "你好_" + loop.getAndIncrement();
            notifyPublisher.publishEvent(msg);
            anotherPublisher.publishEvent(msg);
            TimeUnit.SECONDS.sleep(1);
        }
    }
}
